<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3D旋转轮播</title>
    <style>
        /*清楚页面中素有元素的margin 和padding 值*/
        * {
            margin: 0;
            padding: 0;
        }

        /* 一、设定容器的大小， 位置等信息 */
        .slider{
            width: 600px;
            height: 300px;
            position: relative;
            margin: 150px auto;
        }
        /* 一、设定容器的大小， 位置等信息 */
        .slider-outer {
            width: 600px;
            height: 300px;
            position: relative;
            margin: 150px auto;
            transform-style: preserve-3d;
            transform:  rotateX(-30deg) rotateY(-10deg);
        }

        /* 二、设定容器内元素的占比*/
        .slider-item {
            width: 100px;
            height: 100%;
            position: absolute;
            transform-style: preserve-3d;
            transition: 2s;

        }

        /* 三、 设定轮播的图片的背景信息*/
        .imge{
            width: 100%;
            height: 100%;
            position: absolute;
        }

        .imge:nth-child(1) {
            background-image: url(images/1-1.jpg);
            transform: rotateY(0deg) translateZ(50px);
        }

        .imge:nth-child(2) {
            background-image: url(images/1-2.jpg);
            transform: rotateY(90deg) translateZ(50px);
        }

        .imge:nth-child(3) {
            background-image: url(images/1-3.jpg);
            transform: rotateY(180deg) translateZ(50px);
        }

        .imge:nth-child(4) {
            background-image: url(images/1-4.jpg);
            transform: rotateY(270deg) translateZ(50px);
        }
        /*.top{*/
            /*width: 100px;*/
            /*height: 100px;*/
            /*position: absolute;*/
            /*background-color: red;*/
            /*transform: rotateX(90deg) translateZ(50px);*/
        /*}*/

        .btns {
            position: absolute;
            top: 125px;
            width: 100%;
        }

        .prev, .next {
            width: 50px;
            height: 50px;
            position: absolute;
            color: #fff;
            background: rgba(0, 0, 0, 0.3);
            text-align: center;
            line-height: 50px;
            font-size: 30px;
        }

        .prev {
            left: 0;
        }

        .next {
            right: 0;
        }
    </style>
</head>
<body>
<div class="slider">
    <div class="slider-outer">
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>
        <div class="slider-item">
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="imge"></div>
            <div class="top"></div>
        </div>

    </div>
    <div class="btns">
        <div class="prev" id="prev">&lt;</div>
        <div class="next" id="next">&gt;</div>
    </div>
</div>
<script>
    var num = 0;
    var images = document.getElementsByClassName("slider-item");
    for (var i = 0; i < images.length; i++) {
        var dom = images[i];
        dom.style["left"] = dom.offsetWidth * i + "px";
        dom.style["transitionDelay"] = i * 0.1+ "s";
        var sub = dom.children;
        for (var j = 0; j < sub.length; j++) {
            var subDom = sub[j];
            subDom.style["backgroundPosition"] = -dom.offsetWidth * i + "px";
        }
    }
    document.getElementById("next").addEventListener("click", function (e) {
        var rotate = ++num * 90;
        for (var i = 0; i < images.length; i++) {
            var dom = images[i];
            dom.style["transform"] = "rotateY(" + rotate + "deg)";
        }
    });
    document.getElementById("prev").addEventListener("click", function (e) {
        var rotate = --num * 90;
        for (var i = 0; i < images.length; i++) {
            var dom = images[i];
            dom.style["transform"] = "rotateY(" + rotate + "deg)";
        }
    })

</script>
</body>
</html>